<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>模板管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="assets/layui/css/layui.css">
	<link rel="stylesheet" href="assets/css/all.css" />
</head>
<body class="form-manage">
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
		  <script src="assets/js/html5.min.js"></script>
		  <script src="assets/js/respond.min.js"></script>
		<![endif]-->
	<span class="layui-breadcrumb">
		<a>询残系统</a>
		<a><cite>自定义表单管理</cite></a>
	</span>
	<!--<div class="dashboard">
		<div class="forms-section clearfix" id="forms_section">
			<div class="create-new dashboard-item">
				<a title="创建模板" href="editForm.html">
					<img class="plus-icon" src="assets/img/plus.png" alt="新建" style="display: inline;">
				</a>
			</div>
			<div id="formList" class="cover-list">
				<div class="form dashboard-item">
					<a href="javascript:void(0)">
						<div class="checks check-icons">
							<i class="fa fa-check-square"></i>
						</div>
						<div class="name">***保险公司发布模板</div>
					</a>
				</div>
			</div>
		</div>
	</div>-->
	<div class="admin-main layui-anim layui-anim-upbit">
	    <table class="layui-table" id="list" lay-filter="list"></table>
	</div>
	<script type="text/html" id="action">
	    <a href="{:url('field')}?id={{d.id}}" class="layui-btn layui-btn-normal layui-btn-xs">模型字段</a>
	    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>
	    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
	<script type="text/html" id="status">
	    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|禁用" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
	</script>
	<div class="layui-form">
		<button class="layui-btn add-model">增加新模板</button>
	</div>
	<script src="assets/layui/layui.js"></script>
	<script src="assets/js/all.js"></script>
	<script>
	    layui.use(['table','form','layer'], function() {
	        var table = layui.table, form=layui.form,$ = layui.jquery,layer = layui.layer;
	        var tableIn = table.render({
	            elem: '#list',
	            url: 'assets/data/modelData.json',
	            page:true,
	            cols: [[
	                {field: 'id', title: '编号', width:60, fixed: true},
	                {field: 'title', title: '模型名称', width: 120},
	                {field: 'name', title: '表名', width: 100},
	                {field: 'description', title: '详述', width: 180},
	                {field: 'status', align: 'center',title: '状态', width: 80,toolbar: '#status'},
	                {width: 200, align: 'center', toolbar: '#action'}
	            ]]
	        });
	        form.on('switch(status)', function(obj){
	            loading =layer.load(1, {shade: [0.1,'#fff']});
	            var id = this.value;
	            var status = obj.elem.checked===true?1:0;
	            $.post('{:url("moduleState")}',{'id':id,'status':status},function (res) {
	                layer.close(loading);
	                if (res.status==1) {
	                    tableIn.reload();
	                }else{
	                    layer.msg(res.msg,{time:1000,icon:2});
	                    return false;
	                }
	            })
	        });
	        table.on('tool(list)', function(obj) {
	            var data = obj.data;
	            if(obj.event === 'del'){
	                layer.confirm('你确定要删除该模型吗？', {icon: 3}, function (index) {
	                    $.post("{:url('del')}",{id:data.id},function(res){
	                        if(res.code==1){
	                            layer.msg(res.msg,{time:1000,icon:1});
	                            tableIn.reload();
	                        }else{
	                            layer.msg(res.msg,{time:1000,icon:2});
	                        }
	                    });
	                    layer.close(index);
	                });
	            }
	        });
	        //增加新模板
	        $(".add-model").on("click",function(){
	        	var index = layer.open({
						type: 2,
						title: '编辑表单',
						fixed: false, //不固定
						maxmin: true,
						content: 'editForm.html' // + data.id
					});
					layer.full(index);
	        })
 
	    })
	</script>
	
</body>
</html>